package com.study.spring.proxy.core;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class SaosHttpFactoryBean<T> implements FactoryBean<T> {


    public SaosHttpFactoryBean(Class<T> saosHttpClient){
        this.saosHttpClient=saosHttpClient;
    }

    private Class saosHttpClient;



    @Override
    public T getObject() throws Exception {
        SaosHttpClientInvocationHandler handler = new SaosHttpClientInvocationHandler();
        return  (T)Proxy.newProxyInstance(SaosHttpFactoryBean.class.getClassLoader(), new Class[]{saosHttpClient}, handler);
    }

    @Override
    public Class<?> getObjectType() {
        return saosHttpClient;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
